package cn.com.blueInfo.bpm.template.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.template.request.AutomationRuleDTO;
import cn.com.blueInfo.bpm.template.response.AutomationRuleVO;
import cn.com.blueInfo.bpm.template.service.AutomationRuleService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 自动化规则表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:41:15
 */
@Tag(name = "自动化规则 接口")
@RestController
@RequestMapping("/template/automationRule")
public class AutomationRuleController extends BaseController {

    @Autowired
    private AutomationRuleService automationRuleService;

    /**
     * 新建自动化规则
     * @param automationRuleDTO 自动化规则参数
     * @return ResultInfo
     */
    @Operation(summary = "新增自动化规则")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createAutomationRule(
            @Validated({Create.class, Default.class}) @RequestBody AutomationRuleDTO automationRuleDTO) {
        return automationRuleService.addAutomationRule(automationRuleDTO);
    }

    /**
     * 批量新建自动化规则
     * @param automationRuleDTOList 自动化规则参数列表
     * @return ResultInfo
     */
    @Operation(summary = "批量新建自动化规则")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> batchCreateAutomationRule(
            @Validated({Create.class, Default.class}) @RequestBody List<AutomationRuleDTO> automationRuleDTOList) {
        return automationRuleService.batchAddAutomationRule(automationRuleDTOList);
    }

    /**
     * 根据ID删除自动化规则
     * @param automationRuleId 自动化规则ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除自动化规则")
    @DeleteMapping("/removeInfo/{automationRuleId}")
    public ResultInfo<Integer> deleteAutomationRuleById(
            @Parameter(name = "ID") @PathVariable Long automationRuleId) {
        return automationRuleService.removeAutomationRule(automationRuleId);
    }

    /**
     * 批量根据ID删除自动化规则
     * @param automationRuleIdList 自动化规则ID列表
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除自动化规则")
    @DeleteMapping("/removeInfoList/{automationRuleIdList}")
    public ResultInfo<Integer> batchDeleteAutomationRuleById(
            @Parameter(name = "ID") @PathVariable List<Long> automationRuleIdList) {
        return automationRuleService.batchRemoveAutomationRule(automationRuleIdList);
    }

    /**
     * 根据ID全量更新自动化规则
     * @param automationRuleId 自动化规则ID
     * @param automationRuleDTO 自动化规则参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新自动化规则")
    @PutMapping("/modifyInfo/{automationRuleId}")
    public ResultInfo<Integer> updateAutomationRuleFull(
            @Parameter(name = "ID") @PathVariable Long automationRuleId,
            @Validated({Update.class, Default.class}) @RequestBody AutomationRuleDTO automationRuleDTO) {
        validateUpdateId(automationRuleId, automationRuleDTO.getId());
        return automationRuleService.modifyAutomationRule(automationRuleDTO);
    }

    /**
     * 根据ID部分更新自动化规则
     * @param automationRuleId 自动化规则ID
     * @param automationRuleUpdatePartialDTO 自动化规则参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新自动化规则")
    @PatchMapping("/modifyPartialInfo/{automationRuleId}")
    public ResultInfo<Integer> updateAutomationRulePartial(
            @Parameter(name = "ID") @PathVariable Long automationRuleId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            AutomationRuleDTO.UpdatePartialDTO automationRuleUpdatePartialDTO) {
        validateUpdateId(automationRuleId, automationRuleUpdatePartialDTO.getId());
        return automationRuleService.modifyAutomationRulePartial(automationRuleUpdatePartialDTO);
    }

    /**
     * 根据ID查询自动化规则
     * @param automationRuleId 自动化规则ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询自动化规则")
    @GetMapping("/getInfo/{automationRuleId}")
    public ResultInfo<AutomationRuleVO> getAutomationRuleById(
            @Parameter(name = "ID") @PathVariable Long automationRuleId) {
        return automationRuleService.queryAutomationRuleById(automationRuleId);
    }

    /**
     * 分页查询自动化规则
     * @param automationRuleQueryDTO 自动化规则参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询自动化规则")
    @GetMapping("/getInfos")
    public ResultInfo<Page<AutomationRuleVO>> getAutomationRulePage(
            @Validated AutomationRuleDTO.QueryDTO automationRuleQueryDTO) {
        return automationRuleService.queryAutomationRulePage(automationRuleQueryDTO);
    }

    /**
     * 根据条件查询自动化规则
     * @param automationRuleQueryDTO 自动化规则参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询自动化规则")
    @GetMapping("/getInfoList")
    public ResultInfo<List<AutomationRuleVO>> getAutomationRuleList(
            @Validated AutomationRuleDTO.QueryDTO automationRuleQueryDTO) {
        return automationRuleService.queryAutomationRuleList(automationRuleQueryDTO);
    }

}
